package gameUtils;
import gameExceptions.*;

public class MinLockedSelectionStack extends Stack{
	
	
	
	public int stackNumber;
	public LockedSelectionStackNode topEntity;
	
	public void setSelectable(){
	 topEntity.isSelectable = (topEntity.isSelectable)?false:true;
	}
	public boolean lessThan(LockedSelectionStackNode argumentEntity){
		
	//	This is made with the assumption that no numbers will be alike...
		System.out.println(topEntity.nodeValue.compareTo(argumentEntity.nodeValue));
		return (topEntity.nodeValue.compareTo(argumentEntity.nodeValue) == -1)?false:true;
		
		
		
	}
	
	public boolean isEmpty(){
		return (size==0)?true:false;
	}
	
	public void push(LockedSelectionStackNode newEntity) throws MinLockException{
		/*
		 * 
		 *  make sure that the piece is less than the top node
		 *  make the current top node unable to be selected
		 *  add new entry as topnode
		 *  change the stackLocation for newEntry
		 * 
		 */
		if(isEmpty()){
			topEntity = newEntity;
			size++;
		}else{
			if(this.lessThan(newEntity)){
				newEntity.setNextNode(this.topEntity);
				topEntity = newEntity;
				size++;
			}else{
				throw new MinLockException();
			}
		
		}
	}
	
	public LockedSelectionStackNode peek(){
		if(this.isEmpty()){
			System.out.println("Ive got Nothing");
		}
			return topEntity;
	}
	
	
	public LockedSelectionStackNode pop() throws EmptyStackException{
		/*
		 * detach the topNode
		 * make that topNode.nextNode the new topNode
		 * make that topNode.nextNode selectable
		 * 
		 */
		if(this.isEmpty()){
			throw new EmptyStackException();
		}
		LockedSelectionStackNode temp = topEntity;
		if(size > 1){
		topEntity = topEntity.getNextNode();
		topEntity.isSelectable = true;
		temp.setNextNode(null);
		size--;
		}else{
			topEntity = null;
			size --;
		}
		return temp;
	}
	
	public MinLockedSelectionStack(int stackNumber){
		super();
		this.topEntity = null;
		this.stackNumber = stackNumber;
	}
	public String toString(){
		return "Stack Number: "+stackNumber+" Size: " +size;
	}
	
	
}